package com.ruoyi.project.user.usermapper.service.impl;

import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import com.ruoyi.project.user.usermapper.domain.UserMapper;
import com.ruoyi.project.user.usermapper.mapper.UserMapperMapper;
import com.ruoyi.project.user.usermapper.service.IUserMapperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户映射Service业务层处理
 *
 * @author shixiangwen
 * @date 2022-10-11
 */
@Service
@DataSource(DataSourceType.ACCOUNT)
public class UserMapperServiceImpl implements IUserMapperService {
    @Autowired
    private UserMapperMapper userMapperMapper;

    /**
     * 查询用户映射
     *
     * @param id 用户映射ID
     * @return 用户映射
     */
    @Override
    public UserMapper selectUserMapperById(Long id) {
        return userMapperMapper.selectUserMapperById(id);
    }

    @Override
    public UserMapper queryUserMapper(String appId, String userId) {
        UserMapper query = new UserMapper();
        query.setAppId(appId);
        query.setThirdType("kk");
        query.setThirdUserId(userId);
        List<UserMapper> userMappers = userMapperMapper.selectUserMapperList(query);
        if (!userMappers.isEmpty()) {
            return userMappers.get(0);
        }
        return null;
    }

    /**
     * 查询用户映射列表
     *
     * @param userMapper 用户映射
     * @return 用户映射
     */
    @Override
    public List<UserMapper> selectUserMapperList(UserMapper userMapper) {
        return userMapperMapper.selectUserMapperList(userMapper);
    }

    /**
     * 新增用户映射
     *
     * @param userMapper 用户映射
     * @return 结果
     */
    @Override
    public int insertUserMapper(UserMapper userMapper) {
        return userMapperMapper.insertUserMapper(userMapper);
    }

    /**
     * 修改用户映射
     *
     * @param userMapper 用户映射
     * @return 结果
     */
    @Override
    public int updateUserMapper(UserMapper userMapper) {
        return userMapperMapper.updateUserMapper(userMapper);
    }

    /**
     * 删除用户映射对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteUserMapperByIds(String ids) {
        return userMapperMapper.deleteUserMapperByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除用户映射信息
     *
     * @param id 用户映射ID
     * @return 结果
     */
    @Override
    public int deleteUserMapperById(Long id) {
        return userMapperMapper.deleteUserMapperById(id);
    }
}
